-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support passing configuration arguments to CLI::run() #107
Support passing configuration arguments to CLI::run() #107
Conversation
Sorry, I don't understand the motivation of this PR at all. I'm passing in Anyway, your PR would break that. It creates a global dependency into Secondly, I don't get your point on arguments. The argument parsing is already available. I don't understand what you are trying to accomplish here? Also, your code uses the short-array-syntax. That won't work on PHP 5.3. |
Okay, I get it. The ezcConsoleInput could use that. But we do not need a new Parameter for that. We just need to pass it from the $env we already have. |
@theseer thank you for reviewing this PR and your comments!
I am using your library from another script. Hence, I'm not calling e.g. $factory = new \TheSeer\Autoload\Factory();
$rc = $factory->getCLI()->run(array('--', 'some', 'command', 'options'));
Yes, and this is still possible (as the second parameter to Lines 274 to 276 in 02030e6
That's why I have removed it in the calling scripts. However, I can also re-add them like so: $rc = $factory->getCLI()->run(null, $_SERVER);
I'm not quite sure what you mean by a "global dependency". But as laid out above, arbitrary values can still be passed.
Happy to fix those. |
I see. Well, but that would mean that I need to do something like this, right? $factory = new \TheSeer\Autoload\Factory();
$env = [
'HOME' => $_SERVER['HOME'] ?? null,
'HOMEDRIVE' => $_SERVER['HOMEDRIVE'] ?? null,
'HOMEPATH' => $_SERVER['HOMEPATH'] ?? null,
'argv' => ['--', 'some', 'command', 'options',]
]
$rc = $factory->getCLI()->run($env); This is of course much more complicated, than just adding my options: $factory = new \TheSeer\Autoload\Factory();
$rc = $factory->getCLI()->run(['--', 'some', 'command', 'options',]); Also, I'm not sure that with your solution the $factory = new \TheSeer\Autoload\Factory();
$env = [
'HOME' => $_SERVER['HOME'] ?? null,
]
$rc = $factory->getCLI()->run($env); As |
The very concept of a "super globals" was a design mistake and should never have made it into PHP as it leaks global state. Which is bad. Hence me passing in the $_SERVER array. You are free to provide any type of array you feel like when using it. It should contain the required environment variables that can be expected in CLI context. |
Furthermore I believe that you now pass an array (even just an empty one) to |
That's correct and intended. I despise access to global state. |
I see. So you prevent doing it by doing it yourself. 😉 Anyway. Thanks for change. 🙏 |
Yes and No.
Would be enough if you're in CLI context yourself.
Valid point. Fixed. |
Not sure how you mean this. Of course one has to get the Information from somewhere, but the only time I access it, is in the global state of the bootstrap script. The actual application never sees the global state, as it should be. |
@theseer This is a request for comment!
I've noticed you have added the
$env
parameter for therun()
method.It is not clear to me, why you would pass a super-global (i.e.
$_SERVER
) as a parameter, unless the parameter could also be different. Now, in the current code, there is no other use. Has that been to allow external scripts to provide the environment?Similar to the PR regarding exit codes, it would be awesome to have the possibility to pass the options as a parameter to
run()
, rather than have to mess with the$_SERVER['argv']
variable. That's why I had added the$options
a while ago (unfortunately I forgot to create a PR).I'm happy to the flip the
$options
and$env
parameters. However, unless there is a known use-case, I find that the$env
parameter us probably less likely to be overwritten, given that it's only used to evaluate the home directory.What is your view on this? Would you see my PR as useful, as it is (but officially breaking backwards-compatibility) or shall I flip the parameters? Or do you have yet another idea?
PS: also speaking German, if that would be an issue at all! :-)